<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
    <meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,viewport-fit=cover">
<link rel="stylesheet" href="../../static/assets/css/zpui.css"/>
<link rel="stylesheet" href="../../static/assets/css/all.css"/>
<link rel="stylesheet" href="../../static/mobile/default/css/layout.css"/>

<script src="../../static/assets/js/lib/jquery-2.1.4.js"></script>
<script src="../../static/assets/js/jquery-weui.min.js"></script>
<script src="../../static/assets/js/lib/fastclick.js"></script>
<script src="../../static/assets/js/page.js"></script>
<script src="../../static/js/art-template.js"></script>
<script src="../../static/mobile/default/js/page.js?v=1"></script>
<link rel="stylesheet" href="../../static/mobile/default/css/payment.css" />
    <title> 提货 </title>
</head>
<script type="text/javascript">
    var orderTotal = 0,
        shippingFee = 0,
        bonus_money = 0,
        totalGoodsPrice = 0,
        used_bonus_id = 0;
    var offlineChoose = false;
    var supplyerShippingFee = new Object();
    var is = 0;
</script>
<body>
<style>
    .sss1{
        width: 100vw !important;
        position:absolute;
        left:20px;
    }
</style>
<div class="page">

    <div class="page-hd">
        <div class="header bor-1px-b">
    <div class="header-left">
        <a href="javascript:history.go(-1)" class="left-arrow"></a>
    </div>
    <div class="header-title">提货</div>
    <div class="header-right">
        <a href="#"></a>
    </div>
    </div>
    </div>
        <div class="top addressBox">
    <!-- 没收货地址 -->
    <a href="javascript:;" class="tips fs30 fw_b color_9 sss1">你还没有收货地址，<span class="color_3">去添加</span></a>
    <!-- 收货地址 -->
    <a href="javascript:;" class="address sss2">
        <div><p class="fs30 fw_b color_3 _consignee"></p><span class="fs28 color_9 _address"></span>
            <input type="hidden" id="address_id" value="0">
        </div>
        <img src="../../static/mobile/default/images/rightIcon.png" alt="">
    </a>
</div>
<link rel="stylesheet" href="../../static/mobile/default/css/myaddress.css?v=2">
<link rel="stylesheet" href="../../static/mobile/default/css/cityPicker.css">
<link rel="stylesheet" href="../../static/mobile/default/css/userData.css" />

<script type="text/html" id="addressListTpl">
    <div class="wrapper addressesList " id="boxlists" style="overflow: auto;">
                <div class="page">
            <div class="page-hd" id="boxlist">
                <div class="header bor-1px-b">
                    <div class="header-left">
                        <a href="javascript:;" class="left-arrow close_wrapper" data-type="list"></a>
                    </div>
                    <div class="header-title">选择地址</div>
                    <div class="header-right"></div>
                </div>
            </div>
                        <div class="page-bd">
                <ul class="addresslist goodslist">

                </ul>
            </div>
            <div class="page-ft" id="bottom" style="position: fixed;width: 100vw;bottom: 0;background:#fff;border-top: 1px solid rgba(0,0,0,.1)">
                <a href="javascript:;" class="fs32 fw_b color_w BGcolor_r add_address">新增收货地址</a>
            </div>
        </div>
    </div>

    <div class="wrapper addressInfoBox">

    </div>
</script>
<script src="../../static/js/jquery/jquery-weui.min.js"></script>

<!--地址列表-->

<script type="text/html" id="addressLiTpl">
    {{each list as item index}}
    <li>
        {{if index == '0' }}
        <div class="top block" data-index="{{index}}">
            <div class="address" data-index="{{index}}">
                <div class="info">
                    <div>
                        <p class="fs30 fw_b color_3">{{item.consignee}} {{item.mobile}}</p>{{if item.is_default==1 }} <span class="fs22 color_w BGcolor_r">默认</span>{{/if}}
                        <div class="radioBox">

                            <a href="javascript:;" class="edit fs26 color_9" data-index="{{index}}"><img src="../../static/mobile/default/images/edit.png" alt=""><em>编辑</em></a>
                        </div>
                    </div>
                    <span class="fs28 color_9">{{item.merger_name}}{{item.address}}</span></div>

            </div>
        </div>
        {{else}}
        <object>
                <div class="block" data-index="{{index}}">
                    <div class="address" data-index={{index}}">
                        <div class="info">
                            <div>
                                <p class="fs30 fw_b color_3">{{item.consignee}} {{item.mobile}}</p>{{if item.is_default==1 }} <span class="fs22 color_w BGcolor_r">默认</span>{{/if}}
                                <div class="radioBox">

                                    <a href="javascript:;" class="edit fs26 color_9" data-index="{{index}}"><img src="../../static/mobile/default/images/edit.png" alt="">编辑</a>
                                </div>
                            </div>
                            <span class="fs28 color_9">{{item.merger_name}}{{item.address}}</span></div>

                    </div>


                </div>
                <div class="swiped BGcolor_3">
                    <div class="delect" data-address_id="{{item.address_id}}"><img src="../../static/mobile/default/images/delectIcon.png" alt=""></div>
                </div>
            </object> {{/if}}

    </li>
    {{/each}}
</script>

<!--编缉或添加地址-->

<script type="text/html" id="addressInfoTpl">

    <div class="page-hd">
        <div class="header bor-1px-b">
            <div class="header-left">
                <a href="javascript:;" class="left-arrow close_wrapper" data-type="list"></a>
            </div>
            <div class="header-title">{{if address_id }}修改地址{{else}}添加地址{{/if}}</div>
            <div class="header-right" onclick="evalPost();">保存</div>
        </div>
    </div>
    <form action="" id="formAddress">
        <div class="page-bd ">
            <!-- 页面内容-->
            <div class="cells">
                <div class="cell">
                    <div class="cell_bd"><span class="fs28 color_9">收货人</span></div>

                    <div class="cell_ft">
                        <input type="text" class="fs28  color_3" placeholder="请输入收货人姓名" name="consignee" value="{{consignee}}">
                    </div>
                </div>
                <div class="cell">
                    <div class="cell_bd">
                        <span class="fs28 color_9">手机号码</span></div>
                    <div class="cell_ft">
                        <input type="text" class="fs28  color_3" placeholder="请输入收货人电话" name="mobile" value="{{mobile}}">
                    </div>
                </div>
                <div class="cell bankType cell_access">
                    <div class="cell_bd">
                        <span class="fs28 color_9">所在地区</span></div>
                    <div class="cell_ft">
                        <input type="text" value="{{_merger_name}}" placeholder="请选择所在区域" class="fs28 fw_b color_3 bankBox" readonly="" id="city-picker" data-code="{{district}}" data-codes="{{province}},{{city}},{{district}}">
                    </div>
                </div>
                <div class="cell">
                    <div class="cell_bd">
                        <span class="fs28 color_9">详细地址</span></div>
                    <div class="cell_ft">
                        <input type="text" class="fs28  color_3" placeholder="请输入详细地址" name="address" value="{{address}}">
                    </div>
                </div>
                <div class="cell">
                    <div class="cell_bd">
                        <span class="fs28 color_9">是否设置为默认地址</span></div>
                    <div class="cell_ft">
                        {{if is_default==1}}
                        <input type="checkbox" name="is_default" id="male" value="1" checked class="chooseBtn" /> {{else}}
                        <input type="checkbox" name="is_default" id="male" value="1" class="chooseBtn" /> {{/if}}
                        <label for="male" class="choose-label"></label>
                    </div>
                </div>
            </div>
            <input type="hidden" name="address_id" value="{{address_id}}">

            <div class="page-ft userData">
                <!--<a class="fs32 color_w fw_b BGcolor_r postAddress" onclick="evalPost();">{{if address_id }}确认修改{{else}}确认添加{{/if}}</a>-->
                {{if address_id }}
                <a class="fs32 color_w fw_b BGcolor_r delect" data-address_id="{{address_id}}">删除地址</a> {{/if}}
            </div>
        </div>
        </div>
        </from>
</script>

<script type="text/javascript">
    var isAddOrder = '1';
    var addressList = {};
    var defAddressId = 0;
    $(function() {
        $("body").append(template('addressListTpl'));
        var bottom_h = $("#bottom").height();
        var window_height  = $(window).height();
        var boxlist_h = $("#boxlist").height();
        var header_h = $(".header").height();
        if(isAddOrder == 1)  header_h = 0;
        var h = window_height - bottom_h - header_h;
        $("#boxlists").css('height',h + 'px');
    })

    //获取收货地址区列表
    function getAddressList() {

        var address_id = $('#address_id').val();
        jq_ajax('/member/api.address/getlist.html', 'address_id=' + address_id, function(res) {
            if (res.code == 0) {
                _alert(res.errmsg);
                return false;
            }
            addressList = res.list;
            if (isAddOrder == 1) {

                if (typeof(res.list) == 'undefined') {
                    $('.addressBox .tips').show();
                    $('.addressBox .address').hide();
                    return false;
                }


                if (address_id == 0) {
                    showAddress(addressList[0]);
                    evalShippingFee(); //计算运费
                }

                defAddressId = addressList[0]['address_id'];
            }

            $('.addresslist').html(template('addressLiTpl', res));
            container('.addresslist object')
        })
    }

    //设置显示指定收货地址
    function showAddress(address) {
        $('.address').find('._consignee').html(address.consignee + ' ' + address.mobile);
        $('.address').find('._address').html(address.merger_name + ' ' + address.address);
        $('#address_id').val(address.address_id);
    }

    $(function() {
            getAddressList();
        })
        //点击删除地址
    $(document).on('click', '.addresslist .delect', function() {
            jq_ajax('/member/api.address/delete.html', 'address_id=' + $(this).data('address_id'), function(res) {
                if (res.code == 0) {
                    alert(res.errmsg);
                    return false;
                }
                addressList = res.list;
                $('.addresslist').html(template('addressLiTpl', res));
                container('.addresslist object');
                window.location.href = res.url
            })
        })
        //编辑页删除地址
    $(document).on('click', '.userData .delect', function() {
            jq_ajax('/member/api.address/delete.html', 'address_id=' + $(this).data('address_id'), function(res) {
                if (res.code == 0) {
                    alert(res.errmsg);
                    return false;
                }
                addressList = res.list;
                $('.addresslist').html(template('addressLiTpl', res));
                container('.addresslist object');
                $('html').removeClass('noscroll');
                $('.addressInfoBox').removeClass('move-left');
            })
        })
        //关闭编缉弹出
    $(document).on('click', '.addressInfoBox .close_wrapper', function() {
        $('html').removeClass('noscroll');
        $('.addressInfoBox').removeClass('move-left');
    })

    //点击新增地址
    $(document).on('click', '.add_address', function() {
            $('html').addClass('noscroll');
            $('.addressInfoBox').html(template('addressInfoTpl'));
            $('.addressInfoBox').addClass('move-left');
            $("#city-picker").cityPicker({
                title: "请选择省市区"
            });
        })
        //点击编缉收货地址
    $(document).on('click', '.addresslist .edit', function() {
            isContainer = true;
            $('.addressInfoBox').html(template('addressInfoTpl', addressList[$(this).data('index')]));
            $('html').addClass('noscroll');
            $('.addressInfoBox').addClass('move-left');
            $("#city-picker").cityPicker({
                title: "请选择省市区"
            });
        })
        //提交修改或添加操作
    function evalPost() {
        var postData = $('#formAddress').toJson();
        postData.regionIds = $('#city-picker').attr('data-codes');
        var url = postData.address_id > 0 ? '/member/api.address/edit.html' : '/member/api.address/add.html';
        jq_ajax(url, postData, function(res) {
            if (res.code == 0) {
                _alert(res.errmsg);
                return false;
            }
            $('.addressBox .tips').hide();
            $('.addressBox .address').show();
            addressList = res.list;
            $('.addresslist').html(template('addressLiTpl', res));
            container('.addresslist object');
            $('.addressInfoBox .close_wrapper').trigger("click");
            getAddressList();
        })
    }
    //设置为默认地址
    $(document).on('click', '.addresslist .editDefault', function() {
        var obj = $(this);
        if (defAddressId != obj.val()) {
            jq_ajax('/member/api.address/editdefault.html', 'address_id=' + $(this).val(), function(res) {
                if (res.code == 0) {
                    _alert(res.errmsg);
                    return false;
                }
                defAddressId = obj.val();
            })
        }

    })
</script>
<script type="text/javascript">
    //计算运费

    function evalShippingFee(){
        if(is == 0 ){
            return false;
        }
		var arr = new Object;
        arr.address_id = $('#address_id').val();
		arr.recids = rec_id;
        $('.shippingFee').html('<span style="font-size:80%;">运费计算中...</span>');
        jq_ajax('/shop/api.flow/evalshippingfee.html',arr,function (res) {
            if (res.code==0){
                $('.shippingFee').html(res.errmsg);
                return false;
            }
            shippingFee = res.shippingFee.shipping_fee;
            supplyerShippingFee = res.shippingFee.supplyerShippingFee;
            evalPrice();
        })
    }
    //显示收货地址
    $(document).on('click','.addressBox', function () {
        $('html').addClass('noscroll');
        $('.addressesList').addClass('move-left');
    });
    //关闭弹出
    $(document).on('click','.addressesList .close_wrapper', function () {
        $('html').removeClass('noscroll');
        $('.addressesList').removeClass('move-left');
    })
    //点击选择收货地址
    $(document).on('click', '.addresslist .block', function () {
        var address_id = $('#address_id').val();
        if(address_id < 1){
            $('.sss1').css('display','none');
        }
        if (isAddOrder == 0) return false;
        var obj = $(this);
        setTimeout(function () { //在单击事件中添加一个setTimeout()函数，设置单击事件触发的时间间隔
            if (isContainer == true) {
                return isContainer = false;
            }
            showAddress(addressList[obj.data('index')]);
            $('.close_wrapper').trigger("click");
            getAddressList();
            evalShippingFee();
        }, 100);
    })
</script>
    <div class="page-bd">
        <!-- 页面内容-->
        <div class="weui-cells card-box">
            <div class="weui-cell">
                <div class="weui-cell__hd mr10">
                    <img src="/upload/gimg/2020/09/5f68609dd8f41_thumb.jpg" class="img140">
                </div>
                <div class="weui-cell__bd ">
                    <div class="fs28 ellipsisLn1">茅源庆典酒（云仓6瓶/箱）</div>
                    <div class="fs26 mt30">进货价：380</div>
                </div>
            </div>
        </div>
        <div class="weui-cells card-box">
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <div>
                        <span class="fs28 fw600">提货数量</span>
                    </div>
                    <div class="tx_input mt20">
                        <input id="number" type="number" class="weui-input" oninput='quantity(1314)' placeholder="请输入提货数量">
                    </div>
                </div>
            </div>
        </div>
        <div class="weui-btn-area">
            <a href="javascript:;" class="weui-btn weui-btn_primary">确定</a>
        </div>
    </div>
</div>
<script>
    $(function() {
        FastClick.attach(document.body);
        var address_id = $('#address_id').val();
        if(address_id < 1){
            $('.sss1').css('display','none');
        }
    });
</script>
<script>
    var rec_id = "1314";
    $('.weui-btn').on('click',function () {
        let data = {};
        data.address_id = $('#address_id').val();
        if (data.address_id < 1) {
            $.alert('请设置收货地址后，再操作.');
            return false;
        }
        if(!$('#number').val() || $('#number').val() == 0){
            $.alert('数量必须填写.');
            return;
        }
        if($('#number').val() % 1 != 0){
            $.alert('数量必须填写整数.');
            return;
        }
        data.recids = rec_id;
        data.buy_msg = "";
        data.pay_id = "2";
        data.used_bonus_id = "0";
        data.type = "delivery";
        $.ajax({
            url:'/shop/api.flow/addorder.html',
            data:data,
            type:"POST",
            success:function(res){
               if(res.code == 1){
                   window.location.href = '/shop/Flow/done/order_id/'+res.order_id+'/type/add/types/5.html';
               }else{
                   $.alert(res.errmsg,function () {
                        window.location.href = res.url;
                   })
               }
            }
        })
    })
    function quantity(rec_id){
        
        $.ajax({
            type:'POST',
            data:{
                'rec_id':rec_id,
                'num'   : $('#number').val(),
                'address_id':$('#address_id').val(),
                'type':true,
                'recids':rec_id,
            },
            url:"/shop/api.flow/editnum.html",
            success:function(res){
            }
        })
    }
</script>
</body>
</html>